using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for clsGetMenuAuth
/// </summary>
public class clsGetMenuAuth
{
    private DataTable m_DataTable;
    private bool m_bCheckTable = false;
    private string m_UserID;
    private string m_AutID;
    private string m_MenuID;
    private string m_IsAdmin;
	public clsGetMenuAuth()
	{

	}
    public clsGetMenuAuth(string MenuID)
    {
        HttpContext context = HttpContext.Current;
        m_MenuID = MenuID;
        if (context.Session["AuthTable"] != null)
        {
            m_DataTable = (DataTable)context.Session["AuthTable"];
            m_bCheckTable = true;
        }
    }
    public clsGetMenuAuth(string UserID, string AutID)
    {
        HttpContext context = HttpContext.Current;
        m_UserID = UserID;
        m_AutID = AutID;
        if (context.Session["AuthTable"] != null)
        {
            m_DataTable = (DataTable)context.Session["AuthTable"];
            m_bCheckTable = true;
        }
    }
    public clsGetMenuAuth(string UserID, string AutID,string MenuID)
    {
        HttpContext context = HttpContext.Current;
        m_UserID = UserID;
        m_AutID = AutID;
        m_MenuID = MenuID;
        if (context.Session["AuthTable"] != null)
        {
            m_DataTable = (DataTable)context.Session["AuthTable"];
            m_bCheckTable = true;
        }
    }
    public clsGetMenuAuth(string UserID, string AutID, string IsAdmin, string MenuID)
    {
        HttpContext context = HttpContext.Current;
        m_UserID = UserID;
        m_AutID = AutID;
        m_MenuID = MenuID;
        m_IsAdmin = IsAdmin;
        if (context.Session["AuthTable"] != null)
        {
            m_DataTable = (DataTable)context.Session["AuthTable"];
            m_bCheckTable = true;
        }
    }


    public clsGetMenuAuth(string UserID, string AutID,string MenuID, DataTable AuthTable)
    {
        HttpContext context = HttpContext.Current;
        m_UserID = UserID;
        m_AutID = AutID;
        m_MenuID = MenuID;
        m_DataTable = AuthTable;

    }


    public string mn_MenuID
    {
        get
        {
            return m_MenuID;
        }
        set
        {
            m_MenuID = value;
        }
    }


    public string mn_UserID
    {
        get
        {
            return m_UserID;
        }
        set
        {
            m_UserID = value;
        }
    }

    public string mn_AutID
    {
        get
        {
            return m_AutID;
        }
        set
        {
            m_AutID = value;
        }
    }

    public DataTable mn_DataTable
    {
        get
        {
            return m_DataTable;
        }
        set
        {
            m_DataTable = value;
        }
    }
    public bool mn_bCheckTable
    {
        get
        {
            return m_bCheckTable;
        }
        set
        {
            m_bCheckTable = value;
        }
    }

    public string GetAuthByTable(string strAction)
    {
        string strReturn = "";
        if (m_bCheckTable && m_IsAdmin == "S")
        {
            return "Y";
        }
        else if (m_bCheckTable && m_UserID != "" && m_UserID != null && m_AutID != "" && m_AutID != null && m_MenuID != "" && m_MenuID != null)
        {
            try
            {
                strReturn = m_DataTable.Select("UserID ='" + m_UserID + "' and AutID ='" + m_AutID + "' and MenuID ='" + m_MenuID + "'")[0][strAction].ToString();
            }
            catch (Exception ex) { }
        }
        else if (m_bCheckTable && (m_UserID != "" || m_UserID != null) && m_AutID != "" && m_AutID != null && m_MenuID != "" && m_MenuID != null)
        {
            try
            {
                strReturn = m_DataTable.Select("AutID ='" + m_AutID + "' and MenuID ='" + m_MenuID + "'")[0][strAction].ToString();
            }
            catch (Exception ex) { }
        }
 /*       else if (m_bCheckTable && m_UserID != "" && m_UserID != null && m_AutID != "" && m_AutID != null)
        {
            strReturn = m_DataTable.Select("UserID =" + m_UserID + " and AutID = " + m_AutID + "")[0][strAction].ToString();  
        }
  */

        return strReturn;
    }

    public bool IsAddAuth()
    {
        if (GetAuthByTable("add_mk") == "Y")
            return true;
        else
            return false;
    }

    public bool IsUpdateAuth()
    {
        if (GetAuthByTable("upd_mk") == "Y")
            return true;
        else
            return false;
    }

    public bool IsDeleteAuth()
    {
        if (GetAuthByTable("del_mk") == "Y")
            return true;
        else
            return false;
    }

    public bool IsReportAuth()
    {
        if (GetAuthByTable("rpt_mk") == "Y")
            return true;
        else
            return false;
    }

    public bool IsSendAuth()
    {
        if (GetAuthByTable("send_mk") == "Y")
            return true;
        else
            return false;
    }

    public bool IsShowAuth()
    {
        if (GetAuthByTable("show_mk") == "Y")
            return true;
        else
            return false;
    }
    public bool IsSignAuth()
    {
        if (GetAuthByTable("sign_mk") == "Y")
            return true;
        else
            return false;
    }
}
